<template>
  <div class="auditlog">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>审核日志</span>
      </div>
      <el-input
        v-model="params.username"
        placeholder="请输入内容"
        @blur="sercc"
      ></el-input>
      <el-button type="primary" style="margin-left: 20px" @click="getLists"
        >搜索</el-button
      >
    </el-card>
    <el-button type="danger" @click="deleteall" class="del">批量删除</el-button>
    <el-table
      :header-cell-style="{ 'text-align': 'center' }"
      border
      ref="multipleTable"
      :data="tableData"
      tooltip-effect="dark"
      style="width: 100%; text-align: center"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55"> </el-table-column>
      <!-- <el-table-column prop="logid" label="审核id" width="80px" align="center">
      </el-table-column> -->
      <el-table-column
        prop="visitor"
        label="来访人"
        align="center"
      >
      </el-table-column>

      <el-table-column
        prop="mobile"
        label="来访人电话"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="card"
        label="来访人身份证号"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="carnumber"
        label="来访人车牌号"
        align="center"
      >
      </el-table-column>

      <el-table-column
        prop="username"
        label="审核人"
        width="120px"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="addtime"
        label="审核时间"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="status"
        label="审核状态"
        width="160px"
        align="center"
      >
      </el-table-column>
      <el-table-column prop="status" label="状态" align="center">
        <template slot-scope="scoped">
          <el-button
            type="success"
            @click="xiangxi(scoped.row.logid)"
            style="margin-right: 15px"
            size="mini"
            >详情</el-button
          >
          <!-- <el-button type="danger" @click="del(scoped.row.logid)" size="mini"
            >删除</el-button
          > -->
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="params.page"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="params.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
    <!-- 详细 -->
    <!-- <el-dialog title="请假详细" :visible.sync="dialogFormVisible">
      <el-form
        :model="ruleForm"
        status-icon
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="来访人" prop="visitor.username">
          <el-input v-model.number="ruleForm.visitor.username"></el-input>
        </el-form-item>
        <el-form-item label="来访人电话" prop="visitor.mobile">
          <el-input v-model.number="ruleForm.visitor.mobile"></el-input>
        </el-form-item>
        <el-form-item label="来访人身份证号" prop="visitor.card">
          <el-input v-model.number="ruleForm.visitor.card"></el-input>
        </el-form-item>
        <el-form-item label="来访人车牌号" prop="visitor.carnumber">
          <el-input v-model.number="ruleForm.visitor.carnumber"></el-input>
        </el-form-item>
        <el-form-item label="来访是由" prop="visitor.reason">
          <el-input v-model.number="ruleForm.visitor.reason"></el-input>
        </el-form-item>
        <el-form-item label="来访开始时间" prop="visitor.starttime">
          <el-input v-model.number="ruleForm.visitor.starttime"></el-input>
        </el-form-item>

        <el-form-item label="来访结束时间" prop="visitor.endtime">
          <el-input v-model.number="ruleForm.visitor.endtime"></el-input>
        </el-form-item>
        <el-form-item label="来访登记时间" prop="visitor.addtime">
          <el-input v-model.number="ruleForm.visitor.addtime"></el-input>
        </el-form-item>
        <el-form-item label="审批人" prop="username">
          <el-input v-model.number="ruleForm.username"></el-input>
        </el-form-item>
        <el-form-item label="审批状态" prop="status">
          <el-input v-model.number="ruleForm.status"></el-input>
        </el-form-item>
        <el-form-item> </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
      </div>
    </el-dialog> -->
  </div>
</template>

<script>
import { auditlog, auditlogshow } from "./../api/auditlog";
import http from "../utils/http";
export default {
  data() {
    return {
      username:'',
      id: "",
      tableData: [],
      //   详细表单
      // ruleForm: {
      //   username: "",
      //   status: "",
      //   v_id: "",
      //   visitor: [
      //     {
      //       username: "",
      //       mobile: "",
      //       card: "",
      //       carnumber: "",
      //       reason: "",
      //       starttime: "",
      //       endtime: "",
      //       addtime: "",
      //     },
      //   ],
      // },
      // 总页数
      total: 0,
      // 页数
      params: {
        page: 1,
        pageSize: 10,
        v_id: "",
        userid: "",
        logid: "",
        username: "",
      },
      multipleSelection: [],
      dialogTableVisible: false,
      dialogFormVisible: false,
      form: {
        name: "",
        region: "",
        date1: "",
        date2: "",
        delivery: false,
        type: [],
        resource: "",
        desc: "",
      },
      formLabelWidth: "120px",
    };
  },
  mounted() {
    this.getLists();
  },
  methods: {
    async scher() {
      console.log(this.id);
      const params = {
        id: this.id,
      };
      const res = await auditlogshow(params);
      console.log(res);
      return;
    },
    sercc() {
      if (this.serce == "") {
        this.getLists();
      }
    },
    //删除
    del(logid) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          let res = await http.get("/api/visit/auditlog/del?logid=" + logid);
          this.$message({
            type: "success",
            message: "删除成功!",
          });
          this.getLists();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    //   渲染
    async getLists() {
      const res = await auditlog(this.params);
      this.tableData = res.data;
      this.total = res.total;
      // 终审判断
      this.tableData.filter(item=>{
        if(this.username == item.username){
            this.tableData = []
            this.tableData.push(v)
        }
      })

      this.tableData.filter((item) => {
        if (item.status == 3) {
          item.status = "未审核";
        } else if (item.status == 2) {
          item.status = "审核中";
        } else if (item.status == 1) {
          item.status = "已通过";
        }
      });
    },
    // 分页
    handleSizeChange(val) {
      this.params.pageSize = val;
      this.getLists();
    },
    handleCurrentChange(val) {
      this.params.page = val;
      this.getLists();
    },
    toggleSelection(rows) {
      if (rows) {
        rows.forEach((row) => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    //   复选框的数据
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    // 批量删除
    deleteall() {
      let ids = [];
      this.multipleSelection.forEach((item) => {
        ids.push(item.logid);
      });
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      }).then(async () => {
        let res = await http.get("/api/visit/auditlog/del?ligid", {
          logid: ids,
        });
        this.getLists();
      });
    },
    // 详情
    xiangxi(logid){
  this.$router.push({
        name: 'AuditLogDetails',
        params: {
          id: logid
        }
      })
    },
    // async xiangxi(logid) {
    //   this.dialogFormVisible = true;
    //   let res = await http.get("/api/visit/auditlog/show?id=" + logid);
    //   if (res.code == "00000") {
    //     this.ruleForm = res.data;
    //   }
    // },
  },
};
</script>

<style lang="less" scoped>
.el-pagination {
  text-align: center;
  margin-top: 10px;
}
/deep/.el-form-item__label {
  vertical-align: middle;
  float: left;
  color: #606266;
  line-height: 40px;
  font-size: 1px;
}
/deep/.el-table .el-table__cell.el-input__inner {
  width: 30%;
  margin-left: 20px;
}
.text {
  font-size: 14px;
}
.del {
  margin: 17px 0px;
}

.item {
  margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both;
}

.box-card {
  width: 100%;
}

/deep/.el-pagination .el-select .el-input .el-input__inner {
  padding-right: 25px;
  border-radius: 3px;
  width: 100px;
}
.el-input {
  width: 20%;
}
</style>
<style lang="less">
.el-table--enable-row-transition .el-table__body td.el-table__cell {
  text-align: center;
}
</style>